def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def nearest_prime_number(word1, word2, word3):
    words_to_num = {
        'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5,
        'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
    }
    num = words_to_num.get(word1, None) * 100 + words_to_num.get(word2, None) * 10 + words_to_num.get(word3, None)
    
    if num is None or num < 100 or num > 999:
        return "Wrong input"
    
    lower_num = num
    while not is_prime(lower_num):
        lower_num -= 1
    
    higher_num = num
    while not is_prime(higher_num):
        higher_num += 1
        
    return lower_num if num - lower_num <= higher_num - num else higher_num

words = input().split()
result = nearest_prime_number(*words)
print(result)
